import { cataItem } from 'src/hook/common/useCatalogType';

export function useCatalogTool () {
  //根据ID查找Label
  const findCatalogLabel = (arr: cataItem[], id: number): string => {
    let label = '';
    if ((arr === null) && (arr === undefined)) {
      return '';
    }

    //遍历
    arr.forEach((el: cataItem) => {
      if (el.id === id) {
        label = el.label;
      }
    });

    return label;
  }

  //根据Label查找ID
  const findCatalogId = (arr: cataItem[], label: string): number => {
    let id = -1;

    if ((arr === null) && (arr === undefined)) {
      return -1;
    }

    //遍历
    arr.forEach((el: cataItem) => {
      if (el.label === label) {
        id = el.id;
      }
    });

    return id;
  }


  return {
    findCatalogLabel,
    findCatalogId
  };
}
